//
//  UITitleInfo.m
//  student
//
//  Created by JCai on 2018/10/8.
//  Copyright © 2018年 higer. All rights reserved.
//

#import "UITitleInfo.h"

@interface UITitleInfo ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *infoLabel;

@end


@implementation UITitleInfo

- (instancetype)initWithFrame:(CGRect)frame vertical:(BOOL)isVertical
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setBackgroundColor:[UIColor clearColor]];
        
        CGRect titleFrame = CGRectMake(14 * SCALING,
                                       (CGRectGetHeight(frame)-20 * SCALING)/2,
                                       80 * SCALING,
                                       20 * SCALING);
        if (isVertical) {
            titleFrame = CGRectMake(0, 10 * SCALING, CGRectGetWidth(frame), 20* SCALING);
        }
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:titleFrame];
        [titleLabel setTextColor:[UIColor blackColor]];
        [titleLabel setFont:[UIFont systemFontOfSize:14.0f * SCALING]];
        [self addSubview:titleLabel];
        self.titleLabel = titleLabel;
        
        CGRect infoFrame = CGRectMake(CGRectGetMaxX(titleFrame),
                                      (CGRectGetHeight(frame)-20 * SCALING)/2,
                                       CGRectGetWidth(frame) - CGRectGetMaxX(titleFrame) - 14 * SCALING,
                                       20 * SCALING);
        if (isVertical) {
            infoFrame = CGRectMake(0, CGRectGetMaxY(titleFrame), CGRectGetWidth(frame),
                                   CGRectGetHeight(frame)-CGRectGetMaxY(titleFrame)-10*SCALING);
        }
        UILabel *infoLabel = [[UILabel alloc] initWithFrame:infoFrame];
        [infoLabel setTextColor:[UIColor grayColor]];
        [infoLabel setFont:[UIFont systemFontOfSize:14.0f * SCALING]];
        [infoLabel setAdjustsFontSizeToFitWidth:YES];
        [self addSubview:infoLabel];
        self.infoLabel = infoLabel;
    }
    return self;
}

#pragma mark -
- (void)setTitle:(NSString *)title
{
    [self.titleLabel setText:title];
}

#pragma mark -
- (void)setInfo:(NSString *)title
{
    [self.infoLabel setText:title];
}

+ (UITitleInfo *)initTitleInfo:(UIView *)view frame:(CGRect)frame title:(NSString *)title
{
    UITitleInfo *titleSwitch = [[UITitleInfo alloc] initWithFrame:frame vertical:NO];
    [titleSwitch setTitle:title];
    [view addSubview:titleSwitch];
    return titleSwitch;
}


+ (UITitleInfo *)initTitleH:(UIView *)view frame:(CGRect)frame title:(NSString *)title
{
    UITitleInfo *titleSwitch = [[UITitleInfo alloc] initWithFrame:frame vertical:YES];
    [titleSwitch setTitle:title];
    [view addSubview:titleSwitch];
    return titleSwitch;
}

- (void)setTitle:(UIFont *)font :(UIColor *)color :(NSTextAlignment)textAlignment
{
    [self.titleLabel setFont:font];
    [self.titleLabel setTextColor:color];
    [self.titleLabel setTextAlignment:textAlignment];
}

- (void)setInfo:(UIFont *)font :(UIColor *)color :(NSTextAlignment)textAlignment
{
    [self.infoLabel setFont:font];
    [self.infoLabel setTextColor:color];
    [self.infoLabel setTextAlignment:textAlignment];
}

@end
